package com.dialog;


import java.util.List;

import model.LTModel;

import org.xutils.DbManager;

import com.friehome.app.R;
import com.utils.Comm;
import com.utils.TTUtils;
import com.widget.SAlertDialog;

import adapter.LTAdapter;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

/**
 * 选择照片来源dialog
 * @author tangtang
 *
 */
public class IPDialog{
	Activity context;
	DialogClickListener photoClickListener;
	
	int p;
	String msg;
	public IPDialog(Activity context,String msg,DialogClickListener photoClickListener) {
		this.context = context;
		this.photoClickListener = photoClickListener;
		
		this.msg = msg;
		
	}
	
	public void showDialog(){
		
			final SAlertDialog dialog = new SAlertDialog(context, R.style.AlertDialogCustom);
			View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_ip, null);
			
			final TextView ipText = (TextView) dialogView.findViewById(R.id.text_ip);
			final TextView pText = (TextView) dialogView.findViewById(R.id.text_p);
			
			dialog.setView(dialogView);
			
			
			dialog.setLp(new LayoutParams(TTUtils.dip2px(context, 320) , LayoutParams.MATCH_PARENT));
			
			dialog.setYes(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					photoClickListener.onBack(ipText.getText().toString(),pText.getText().toString());
				}
			});
			dialog.show();
		
	};
	
	
	public interface DialogClickListener{
		void onBack(String ip,String port);
	}

	
	class BtnClick implements View.OnClickListener{

		@Override
		public void onClick(View v) {
			
			int tag = Integer.parseInt((String) v.getTag());
			p = tag;
			LinearLayout content = (LinearLayout) v.getParent();
			for (int i = 0; i < content.getChildCount(); i++) {
				ImageView img = (ImageView) content.getChildAt(i);
				if (i < tag) {
					img.setImageResource(R.drawable.assess_pre);
				}else{
					img.setImageResource(R.drawable.assess);
				}
			}
			
			
		}
		
	}
}
